// #ifdef H5
const baseUrl='/api';
// #endif

// #ifdef MP-WEIXIN
const baseUrl='http://localhost';
// #endif


const json2url=(json)=>{
	//json {a:1,b:2,c:3};
	let arr=[];
	for(let key in json){ //key a b c   json[key]  1 2 3
		arr.push(key+'='+json[key]) //a=1
	}
	//arr ['a=1','b=2','c=3']
	return arr.join('&') //a=1&b=2&c=3
}
const http=(options)=>{
	if(!options.url){
		console.log('必须要有地址才行')
		return;
	}
	let method=options.method || 'get';
	let data=options.data || {};
	let params=options.params || {};
	
	let json={
		url:baseUrl+options.url+'?'+json2url(params),
		method,
		data
	}
	if(options.success){
		json.success=options.success;
	}
	if(options.fail){
		json.fail=options.fail;
	}
	
	uni.request(json)
}

export default http;

/* 
http({
	url:'/login',
	method:'get|post'  //get是默认
	data:{},
	params:{}, //这个数据放在地址里面
	success:()=>{},
	fail:()=>{}
}) 
 */

/* 
 
 */